import '../model/base/api_result_data.dart';
import '../model/login_model.dart';
import '../utils/dio_utils.dart';
import 'config.dart';

class LoginRequest {
  static Future<ApiResultData<LoginModel>> login(
      String username, String password) async {
    var param = {
      "userName": username,
      "password": password,
      "validateCode": "test",
      "moduleId": 1,
    };
    // 1.发送网络请求
    final url = "/api/users/login";
    final result = await DioUtils.instance
        .requestBaseUrl(url, method: HttpConfig.post, params: param);

    ApiResultData<LoginModel> apiResultData =
        ApiResultData<LoginModel>.fromJson(result, LoginModel.fromJson);
    // 2.json转model
    return apiResultData;
  }

  static Future<ApiResultData<String>> forgotPw(String email) async {
    // 1.发送网络请求
    final url = "/api/users/forgotPwd?eMail=$email";
    final result = await DioUtils.instance.requestBaseUrl(url);

    ApiResultData<String> apiResultData =
        ApiResultData<String>.fromJson(result, (data) => data as String);
    // 2.json转model
    return apiResultData;
  }

  static Future<ApiResultData<String>> resetPw(
      String sId, String newPwd, String confirmPwd) async {
    // 1.发送网络请求
    final url = "/api/Users/resetPwd";
    var param = {
      "sId": sId,
      "password": newPwd,
      "confirmPassword": confirmPwd,
    };
    final result = await DioUtils.instance
        .requestBaseUrl(url, method: HttpConfig.post, params: param);

    ApiResultData<String> apiResultData =
        ApiResultData<String>.fromJson(result, (data) => data as String);
    // 2.json转model
    return apiResultData;
  }
}
